
% %%%%%%%%%%%% Lambda v vs Lamda c%%%%%%%%%%%%

clear all
clc
muc=0.033;
C=40;
Lambdac= 2:0.1:15 ;
T=5;
R=zeros(length(Lambdac),1);
% Waitings=zeros(length(Lambdac),1);
numbers=zeros(length(Lambdac),1);

for j=1:length(Lambdac)
n=ceil(((Lambdac(j) - muc)*T)/(T*C*muc-1));
Lamdav=zeros(n+3,1);
b=zeros(n+3,1);
numbers(j)= n;
  Pv=Gaussiandist(n);
% Pv=decreasingdist(n);
Pc=Gaussiandist(n);
for i=1:n
    b(i)= Lambdac(j)*Pc(i) + (1/T) ;
end
b(n+1)= C*n*muc;
b(n+2)= muc;
b(n+3)=Lambdac(j) + n*(1/T) ;
cond = parameterfunspecial(n,Pv);
for k=1:n+3
    Lamdav(k)=b(k)/cond(k);
    if  Lamdav(k) == Inf
        Lamdav(k)=0;
    end
end
R(j)=max(Lamdav);
% Waitings = zeros(n+3,1);
% for k=1:n
%    Waitings(k)=-bestlamdav*cond(k)+b(i) ;
% end
% Waitings(n+1)=bestlamdav*cond(n+1)-b(n+1);
% Waitings(n+2)=bestlamdav*cond(n+2)-b(n+2);
% Waitings(n+3)=-bestlamdav*cond(n+3)+b(n+3);
end

plot(Lambdac,R);
hold on

% %%%%%%%%%%%%%%%%%%%% lambdav vs T%%%%%%%%%%%%%%%%
% clear all
% clc
% muc=0.033;
% C=40;
% Lambdac= 5 ;
% T=2:0.1:15;
% R=zeros(length(T),1);
% % Waitings=zeros(length(Lambdac),1);
% numbers=zeros(length(T),1);
% 
% for j=1:length(T)
% n=ceil(((Lambdac - muc)*T(j))/(T(j)*C*muc-1));
% Lamdav=zeros(n+3,1);
% b=zeros(n+3,1);
% numbers(j)= n;
%   Pv=Gaussiandist(n);
% %  Pv=decreasingdist(n);
% Pc=Gaussiandist(n);
% for i=1:n
%     b(i)= Lambdac*Pc(i) + (1/T(j)) ;
% end
% b(n+1)= C*n*muc;
% b(n+2)= muc;
% b(n+3)=Lambdac + n*(1/T(j)) ;
% cond = parameterfunspecial(n,Pv);
% for k=1:n+3
%     Lamdav(k)=b(k)/cond(k);
%     if  Lamdav(k) == Inf
%         Lamdav(k)=0;
%     end
% end
% R(j)=max(Lamdav);
% % Waitings = zeros(n+3,1);
% % for k=1:n
% %    Waitings(k)=-bestlamdav*cond(k)+b(i) ;
% % end
% % Waitings(n+1)=bestlamdav*cond(n+1)-b(n+1);
% % Waitings(n+2)=bestlamdav*cond(n+2)-b(n+2);
% % Waitings(n+3)=-bestlamdav*cond(n+3)+b(n+3);
% end
% 
% plot(T,R);
% hold on


% %%%%%%%%%% 3D %%%%%%%%%%%
% clear all
% clc
% muc=0.033;
% C=40;
% Lambdac= 2:0.1:15 ;
% T=2:0.1:15;
% R=zeros(length(T),length(Lambdac));
% exitss=zeros(length(T),length(Lambdac));
% numbers=zeros(length(T),length(Lambdac));
% for k=1:length(T)
% for j=1:length(Lambdac)
% n=ceil(((Lambdac(j) - muc)*T(k))/(T(k)*C*muc-1));
% numbers(k,j)= n;
% % Pv=Gaussiandist(n);
% Pv=decreasingdist(n);
% Pc=Gaussiandist(n);
% lb=zeros(1,1);
% ub=ones(1,1);
% ub(1)=inf;
% b1=zeros(n+2,1);
% lb(1)=Lambdac(j) + n*(1/T(k)) ;
% for i=1:n
%     b1(i)= Lambdac(j)*Pc(i) + (1/T(k)) ;
% end
% b1(n+1)= -C*n*muc;
% b1(n+2)= -muc;
% cond = @(x)parameterfunspecial(x,n,Pv,b1);
% obj=@(x)x(1);
% x0 = ones(1,1);
% x0(1)= Lambdac(j)+ (n/T(k));
% [x,fval,exitflag,output,lambda] = fmincon(obj,x0,[],[],[],[],lb,ub,cond);
% R(k,j)= x(1);
% exitss(k,j)=exitflag;
% end
% end
% surf(Lambdac,T,R)
